package com.gnerv.author.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gnerv.author.dto.CatalogDTO;
import com.gnerv.author.entity.Catalog;
import com.gnerv.author.mapper.CatalogMapper;
import com.gnerv.author.service.ICatalogService;
import com.gnerv.author.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 博客平台-栏目表 服务实现类
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-07-15
 */
@Service
public class CatalogServiceImpl extends ServiceImpl<CatalogMapper, Catalog> implements ICatalogService {

    public static String baseCatalogUrl = "/catalog/";

    @Autowired
    CatalogMapper catalogMapper;

    @Override
    public boolean createCatalog(Catalog catalog) {
        String cId = UUIDUtil.getLower();
        catalog.setbId(cId);
        catalogMapper.insert(catalog);
        return true;
    }

    @Override
    public boolean deleteCatalog(String bId) {
        catalogMapper.delete(new QueryWrapper<>(new Catalog(bId)));
        return true;
    }

    @Override
    public boolean updateCatalog(Catalog catalog) {
        catalogMapper.update(catalog, new QueryWrapper<>(new Catalog(catalog.getbId())));
        return true;
    }

    @Override
    public CatalogDTO selectCatalog(String bId) {
        CatalogDTO catalog = catalogMapper.selectCatalog(bId);
        return catalog;
    }

    @Override
    public List<CatalogDTO> listCatalog(CatalogDTO catalogDTO) {
        List<CatalogDTO> catalogs = catalogMapper.listCatalog(catalogDTO);
        return catalogs;
    }
}
